package controller.menubar.commands;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

public class TerminalListener implements ActionListener  {

	private static String OS = System.getProperty("os.name").toLowerCase();
	
	@Override
	public void actionPerformed(ActionEvent arg0) {
		String command = "";
		
		if (isWindows()) {
			String path = "c:\\";
			try {
				Runtime.getRuntime().exec(new String[] { "cmd.exe", "/C", "\"start; cd "+path+"\"" });
			} catch (IOException e) {
				e.printStackTrace();
			}			
			return;
			
		} else if (isMac()) {
			//command = "";
		} else if (isUnix()) {
			command  = System.getenv().get("SHELL");   	
		} else if (isSolaris()) {
			command  = System.getenv().get("SHELL");   	
		} else {
			System.out.println("Your OS is not support!!");
		}		
		if (command != "" ){
			System.out.println(command);
			Runtime rt = Runtime.getRuntime(); 	
			try {
				rt.exec(command);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}	
		
	}
	
	
	public static boolean isWindows() {
		 
		return (OS.indexOf("win") >= 0); 
	}
 
	public static boolean isMac() { 
		return (OS.indexOf("mac") >= 0); 
	}
 
	public static boolean isUnix() { 
		return (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0 ); 
	}
 
	public static boolean isSolaris() { 
		return (OS.indexOf("sunos") >= 0); 
	}
	

}
